import 'package:base/main.dart';
import 'package:flutter/material.dart';
import 'package:framework/main.dart';
import 'package:module_home/pages/more_manage/more_manager_logic.dart';

class MoreTitleBarWidget extends StatelessWidget {
  MoreManagerLogic logic;

  MoreTitleBarWidget({super.key, required this.logic});

  @override
  Widget build(BuildContext context) {
    Log.d('MoreTitleBarWidget build');
    return Row(
      children: [
        const SizedBox(width: 8),
        const Text(
          "首页功能",
          style: TextStyle(
              fontSize: 14, fontWeight: FontWeight.bold, color: Colors.black),
        ),
        SizedBox(width: 16),
        Obx(() => logic.isEditing
            ? const Text(
                "按住拖动调整顺序",
                style: TextStyle(
                    fontSize: 10,
                    fontWeight: FontWeight.w500,
                    color: Colors.black54),
              )
            : SizedBox.fromSize()),
        Expanded(child: SizedBox.fromSize()),
        InkWell(
          onTap: () {
            logic.restoreDefault();
          },
          child: const Text(
            string_restore_default,
            style: TextStyle(
                fontSize: 12,
                fontWeight: FontWeight.w500,
                color: Colors.black54),
          ),
        ),
        SizedBox(width: 8),
        Container(
          padding: const EdgeInsets.all(Constants.px_1),
          decoration: BoxDecoration(
            color: Color(0xFF1F6FE9),
            borderRadius: BorderRadius.circular(10),
            boxShadow: [BoxShadow(color: Colors.white, blurRadius: 1)],
          ),
          child: Obx(() => logic.isEditing
              ? _buildTextButton(string_save, () {
                  logic.save(context);
                })
              : _buildTextButton(string_eidt, () {
                  logic.toggleEditing();
                })),
        ),
        const SizedBox(width: 8),
      ],
    );
  }

  Widget _buildTextButton(text, final VoidCallback? onPressed) {
    return InkWell(
      onTap: onPressed,
      child: Text("  $text  ",
          style: TextStyle(
              fontSize: 10, fontWeight: FontWeight.w400, color: Colors.white)),
    );
  }
}
